<?php
/**
 * Created by PhpStorm.
 * User: xujiarui
 * Date: 2017/9/10
 * Time: 下午1:43
 */

namespace app\admin\controller;
use \think\Session;
use \think\Cookie;
use \think\Config;
use think\Controller;

class Common extends Controller
{

    protected $beforeActionList = [
        'first',
    ];

    protected function first()
    {
        Cookie::init(['prefix'=>'admin_','path'=>'/','httponly'=>true]);
        $token = Cookie::get('token');
        $check_res = \user\Auth::check($token);
        if($check_res['resCode'] == -8){
            Session::delete('id');
            Session::delete('username');
            Session::delete('username_dsp');
            Cookie::delete('token');
            format(-999,$check_res['msg']);
        }else if ($check_res['resCode'] != 2){
            format(-2,$check_res['msg']);
        }
    }

    public function qiNiu()
    {
        $accessKey = Config::get('qiniu.access_key');
        $secretKey = Config::get('qiniu.secret_key');
        $auth = new \Qiniu\Auth($accessKey, $secretKey);
        $token = $auth->uploadToken(Config::get('qiniu.bucket'));
        echo json_encode(array('uptoken'=>$token));
    }

}